// pages/discount/discount.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    loadingMoreHidden: true,
    goods: [],
    categories: [],
    activeCategoryId: 0,
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {

    var categories = [{ id: 0, name: "雀巢" }, { id: 1, name: "蓝山" }, { id: 2, name: "越南" }, { id: 3, name: "马来西亚" }];

    this.categories = categories;
    var activeCategoryId = 0;
    this.setData({
      categories: categories,
      activeCategoryId: activeCategoryId,
    })
    this.getGoodsList(0)
  },
  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  },
  toDetailsTap: function (e) {
    wx.navigateTo({
      url: "/pages/goods-details/index?id=" + e.currentTarget.dataset.id
    })
  },
  tabClick: function (e) {
    this.setData({
      activeCategoryId: e.currentTarget.id
    });
    this.getGoodsList(this.data.activeCategoryId);
  },
  getGoodsList: function (categoryId) {
    var good = { name: "Nestle雀巢1+2原味奶香特浓无蔗", pic: "https://gss3.bdstatic.com/-Po3dSag_xI4khGkpoWK1HF6hhy/baike/c0%3Dbaike80%2C5%2C5%2C80%2C26/sign=253d9b39f7faaf5190ee89eded3dff8b/aec379310a55b31900e2b16a49a98226cffc1791.jpg", minPrice: 29.90 }
    var goods = []
    var good1 = good
    var good2 = good
    var good3 = good

    if (categoryId == 0) {
      goods[0] = good
    } else if (categoryId == 1) {
      goods[0] = good
      goods[1] = good1
    } else if (categoryId == 2) {
      goods[0] = good
      goods[1] = good1
      goods[2] = good2
    } else if (categoryId == 3) {
      goods[0] = good
      goods[1] = good1
      goods[2] = good2
      goods[3] = good3
    }
    
    this.setData({
      goods: goods,
    })
    console.log(categoryId)

  }
})